<template>
  <div id="car_item">
    <input type="checkbox" class="car_item_check" :checked="cartItem.checked">

    <img :src="cartItem.image" class="caritem_img" @click="alertBtnSelect">
    <div class="car_item_content" @click="alertBtnSelect">
      <div class="car_item_content_title">{{cartItem.title}}</div>
      <div class="car_item_content_subtitle">{{cartItem.desc}}</div>
      <div class="car_item_content_price">
        <span class="car_price_left">￥{{cartItem.realPrice}}</span>
        <span class="car_price_right">x{{cartItem.count}}</span>
      </div>
    </div>
  </div>
</template>

<script>
import {mapGetters} from "vuex";
export default {
  name: "CarItem",
  props:{
    cartItem:{
      type:Object
    }
  },
  data(){
    return{
      myIndex:false,//是否可以全选
    }
  },
  methods:{
    alertBtnSelect(){//单击事件
      this.$store.dispatch('alertChecked',this.cartItem.iid);
      // this.cartItem.checked = !this.cartItem.checked;
      // for (let item of this.getCartList){
      //   if (!item.checked){
      //     this.myIndex=false;
      //     break
      //   }else{
      //     this.myIndex=true;
      //   }
      // }
      // console.log(this.myIndex);
      // this.$store.commit('alertQuanXuanIndex',this.myIndex);
    }
  },
  computed:{
    ...mapGetters([//使用对象展开运算符,将getter混入到computed对象中
      "getCartLength",
      "getCartList"
    ])
  }
}
</script>

<style scoped>
#car_item{
  width: 100%;
  display: flex;
  height: 130px;
  border-bottom: 2px solid #EEEEEE;
  overflow: hidden;
  justify-content: center;
  align-items: center;
}
.car_item_check{
  margin-left: 20px;
}
.caritem_img{
  width: 90px;
  height: 93%;
  margin: 5px 10px;
}
.car_item_content{
  width: calc(100% - 100px);
  padding: 10px 15px;
}
.car_item_content div{
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.car_item_content_title{
  font-size: 20px;
  line-height: 40px;
}
.car_item_content_subtitle{
  font-size: 16px;
  color: #aaaaaa;
  line-height: 20px;
}
.car_item_content_price{
  font-size: 17px;
  line-height: 80px;
}
.car_price_left{
  float: left;
}
.car_price_right{
  float: right;
  margin-right: 30px;
}
</style>
